﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ProtocolBuilder.Model.Field
{
    class SingleConditionField : ComposeField
    {
        public SingleConditionField()
        {
            this.XmlElement.Add(new XAttribute("caseValue", string.Empty));
        }

        public string CaseValue
        {
            //get
            //{
            //    return this.XmlElement.Attribute("caseValue").Value;
            //}
            //set
            //{
            //    this.XmlElement.Attribute("caseValue").Value = value;
            //}
            get { return this.FieldName; }
            set { this.FieldName = value; }
        }

        public override string GenerateSerializeCode()
        {
            StringBuilder sb = new StringBuilder();
            IEnumerable<AbsField> children = this.GetChildrenField();
            foreach (AbsField child in children)
            {
                sb.AppendFormat("{0}{1}", child.GenerateSerializeCode(), TextHelper.HtmlNewLine);
            }

            return sb.ToString();
        }

        public override string GenerateDeserializeCode()
        {
            StringBuilder sb = new StringBuilder();
            IEnumerable<AbsField> children = this.GetChildrenField();
            foreach (AbsField child in children)
            {
                sb.AppendFormat("{0}{1}", child.GenerateDeserializeCode(), TextHelper.HtmlNewLine);
            }

            return sb.ToString();
        }
    }
}